import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate"; // Vuex 数据持久化
Vue.use(Vuex);

// Vuex 数据持久化
const store = new Vuex.Store({
  plugins: [createPersistedState()], //插件
  state: {
    username: null,
    appphone: null,
    userinfo: null,
    cityinfo: null,
    contactInfo: {},
    address:{},
    
  },
  mutations: {
    changeAppPhone(state, payload) {
      state.appphone = payload;
    },
    savecontactInfo(state, payload) {
      state.contactInfo = payload;
    },
    saveAddress(state, payload) {
      state.address = payload;
    },
    changeUsername(state, payload) {
      state.username = payload;
    },
    changeUserInfo(state, payload) {
      state.userinfo = { ...state.userinfo, ...payload };
    },
    resetUserInfo(state) {
      state.userinfo = null;
    },
    changeCityInfo(state, payload) {
      state.cityinfo = payload;
    },
  },
  modules: {},
  actions: {},
});

export default store;
